package fangzhiyi.testbank;

/**
 * @author south wind
 * @version 1.0
 * @date 2025/3/20 19:24
 * @description
 */
public class BankCard {
    //静态变量，用于生成银行卡序号和累计余额
    private static int nextNo =1;//银行卡序号，每发一张卡加1
    private static double totalBalance = 0;//所有卡的累计余额

    //实例变量
    private int cardNo;//银行卡号
    private String name;//客户姓名
    private String personId;//客户身份证号
    private double balance;//卡上余额

    public BankCard( String name, String personId) {
        this.cardNo = cardNo++;//分配银行卡号
        this.name = name;
        this.personId = personId;
        this.balance = 0;//初始余额为0
    }
    //静态办法：获取下一个卡号
    public static int getNextNo() {
        return nextNo;
    }
    //静态方法：获取所有卡的累计余额
    public static double getTotalBalance() {
        return totalBalance;
    }

   //静态办法：获取当前最后的卡号
    public static int getCurrentCardNo(){
        return nextNo -1;
    }
    //获取本卡的余额
    public double getBalance() {
        return this.balance;
    }

    //存款方法
    public void deposit(double amount){
        if (amount >0){
            this.balance += amount;
            totalBalance += amount;//更新所有卡的累计余额
            System.out.println(name+"存款成功，当前余额："+this.balance);
        }else {
            System.out.println("存款金额必须大于0");
        }
    }
    //取款办法
    public void withdraw(double amount){
        if (amount>0 && amount <= this.balance){
            this.balance -= amount;
            totalBalance -= amount;//更新所有卡的累计余额
            System.out.println(name+"取款成功，当前余额："+balance);
        }else {
            System.out.println("取款失败，余额不足或金额无效！");
        }
    }

    //打印银行卡信息
    @Override
    public String toString() {
        return "卡号: " + cardNo + ", 姓名: " + name + ", 身份证号: " + personId + ", 余额: " + balance;
    }
}
